//
//  main.swift
//  linearSearch
//
//  Created by lhc on 2023/2/4.
//

import Foundation

class LinearSearch {
    static func search<T: Equatable>(_ dataList: [T], _ target: T) -> Int {
        for (index, d) in dataList.enumerated() {
            if d == target {
                return index
            }
        }
        return -1
    }
}

let dataList = [24, 18, 12, 9, 16, 66, 32, 4]
let result = LinearSearch.search(dataList, 16)
print(result)


class Student {
    let name: String
    
    init(name: String) {
        self.name = name
    }
}

extension Student: Equatable {
    static func == (lhs: Student, rhs: Student) -> Bool {
        return lhs.name == rhs.name
    }
}

let studentList = [Student(name: "mike"), Student(name: "bobby")]
let bobby = Student(name: "bobby")
let searchStudent = LinearSearch.search(studentList, bobby)
print(searchStudent)
